﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using AutoMapper;
using Boggle;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Common;
using Newtonsoft.Json.Serialization;
using Web.App_Start;
using Web.Controllers.Api;
using Web.Installers;

namespace Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Change default json resolver to be cammel case
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            //create and register the windsor dependency resolver
            WindsorContainer container = new WindsorContainer();
            container.Install(new BoggleInstaller(), new WebInstaller(), new AutoMapperInstaller());
            GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container);

            //intialize automapper
            IEnumerable<Profile> profiles = container.ResolveAll<Profile>();
            AutoMapperConfig.Initialize(profiles);
        }
    }
}